package com.tianqu.tms.www.api.action;

import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

import com.fasterxml.jackson.annotation.JsonGetter;
import com.tianqu.tms.core.base.TmsAjaxAction;
import com.tianqu.tms.core.base.TxController;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.exception.ConnectionException;
import com.tianqu.tms.core.exception.TmsException;
import com.tianqu.tms.core.util.HttpUtil;
import com.tianqu.tms.dao.AucBidhistoryDaoImp;
import com.tianqu.tms.dao.AucManagerDaoImp;
import com.tianqu.tms.dao.TmsDao;
import com.tianqu.tms.dto.AucBidhistoryDto;
import com.tianqu.tms.dto.AucManagerDto;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;

/**
 * Created by wang-ivy on 2016/11/17.
 */
public class TmsTransAucManagementAction extends TmsAjaxAction {
    @Override
    @JsonGetter
    public void process(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response, UserContext uc) throws TmsException {

        AucManagerDaoImp aucManagerDao = (AucManagerDaoImp) AucManagerDaoImp.getInstance(TmsDao.TMS_AUC_MANAGEMENT);
        try {
            //获取app端post的车辆竞价历史信息
        	JSONArray jsonArray = HttpUtil.getClientRequestBody(request);
            List<AucManagerDto> aucManagementList = (List<AucManagerDto>) JSONArray.toList(jsonArray,new AucManagerDto(),new JsonConfig());
            for(AucManagerDto jsonObject:aucManagementList){
                AucManagerDto aucManagerDto = new AucManagerDto();	
                aucManagerDto.setId(jsonObject.getId());
                aucManagerDto.setBidStatus(jsonObject.getBidStatus());
                aucManagerDao.updateBistatusById(aucManagerDto);
            }
           
            responseValues(response,"1", TEXT);
        } catch (IOException e) {
        	responseValues(response, e.getMessage(), TEXT);
            e.printStackTrace();
        }catch(Exception e){
        	responseValues(response, e.getMessage(), TEXT);
        }
    }

}
